home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGNG_C / M2COMP.LZH / INOUT.DEF < prev    next >
Text File  |  1987-06-29  |  5KB  |  183 lines

  1. DEFINITION MODULE InOut;
  2.  
  3. (* (C) Copyright 1987 Fitted Software Tools. All rights reserved. *)
  4.  
  5. (*
  6.     This is the standard module InOut as defined in
  7.     "Programming in Modula-2" by Niklaus Wirth.
  8.  
  9.     A few additionns were made to this modules, mainly
  10.     to add support for LONGINT and LONGCARD data types
  11. *)
  12.  
  13. FROM SYSTEM     IMPORT WORD;
  14. FROM FileSystem IMPORT File;
  15.  
  16. CONST
  17.     EOL = 36C;
  18.  
  19. VAR
  20.     Done    :BOOLEAN;
  21.     termCH  :CHAR;
  22.  
  23. (*
  24.     Done is set to TRUE by the following procedures:
  25.         OpenInput, OpenOutput,
  26.         RedirectInput, RedirectOutput,
  27.         Read,
  28.         ReadWrd, WriteWrd,
  29.         Read, ReadInt, ReadCard,
  30.         ReadLongInt, ReadLongCard,
  31.     to indicate success.
  32. *)
  33.  
  34.  
  35. PROCEDURE OpenInput( defext :ARRAY OF CHAR );
  36. (*
  37.     prompts the user for a file to redirect the input from.
  38.     if the last character in the input is a '.', defext is
  39.     appended to it.
  40. *)
  41.  
  42. PROCEDURE OpenOutput( defext :ARRAY OF CHAR );
  43. (*
  44.     prompts the user for a file to redirect the input to.
  45.     if the last character in the input is a '.', defext is
  46.     appended to it.
  47. *)
  48.  
  49. PROCEDURE RedirectInput( from :ARRAY OF CHAR );
  50. (*
  51.     redirects the input from file from.
  52. *)
  53.  
  54. PROCEDURE RedirectOutput( to :ARRAY OF CHAR );
  55. (*
  56.     redirects the output to file to.
  57. *)
  58.  
  59. PROCEDURE CloseInput;
  60. (*
  61.     the file opened with OpenInput or RedirectInput is closed
  62.     and the terminal is reestablished as the input device.
  63. *)
  64.  
  65. PROCEDURE CloseOutput;
  66. (*
  67.     the file opened with OpenOutput or RedirectOutput is closed
  68.     and the terminal is reestablished as the output device.
  69. *)
  70.  
  71. PROCEDURE Read( VAR ch :CHAR );
  72. (*
  73.     read a character
  74. *)
  75.  
  76. PROCEDURE ReadString( VAR s :ARRAY OF CHAR );
  77. (*
  78.     read a string.
  79.     input is terminated by a ' ', or any control character except BS or DEL.
  80.     the terminating character is saved in termCH.
  81.     when reading from the terminal, editing of the input is available:
  82.         ASCII.BS deletes the last characted input
  83.         ASCII.DEL deletes all characters input
  84.         ASCII.ESC deletes all characters input and returns
  85. *)
  86.  
  87. PROCEDURE ReadLine( VAR s :ARRAY OF CHAR );
  88. (*
  89.     read a line.
  90.     input is terminated by an EOL, EOF or ESC character.
  91.     the terminating character is saved in termCH.
  92.     when reading from the terminal, editing of the input is available:
  93.         ASCII.BS deletes the last characted input
  94.         ASCII.DEL deletes all characters input
  95.         ASCII.ESC deletes all characters input and returns
  96. *)
  97.  
  98. PROCEDURE ReadInt( VAR x :INTEGER );
  99. (*
  100.     a string is read from the input device and is then converted to
  101.     an INTEGER.
  102. *)
  103.  
  104. PROCEDURE ReadCard( VAR x :CARDINAL );
  105. (*
  106.     a string is read from the input device and is then converted to
  107.     a CARDINAL.
  108. *)
  109.  
  110. PROCEDURE ReadWrd( VAR w :WORD );
  111. (*
  112.     read a WORD from the input file.
  113.     legal only if input is being redirected from a file.
  114. *)
  115.  
  116. PROCEDURE Write( ch :CHAR );
  117. (*
  118.     write the character
  119. *)
  120.  
  121. PROCEDURE WriteLn;
  122. (*
  123.     same as: Write( ASCII.EOL )
  124. *)
  125.  
  126. PROCEDURE WriteString( s :ARRAY OF CHAR );
  127. (*
  128.     write the string out
  129. *)
  130.  
  131. PROCEDURE WriteInt( x :INTEGER; n :CARDINAL );
  132. (*
  133.     write the INTEGER right justified in a field of at least n characters.
  134. *)
  135.  
  136. PROCEDURE WriteCard( x, n :CARDINAL );
  137. (*
  138.     write the CARDINAL right justified in a field of at least n characters.
  139. *)
  140.  
  141. PROCEDURE WriteOct( x, n :CARDINAL );
  142. (*
  143.     write x in octal format in a right justified field of at least n characters.
  144.     IF (n <= 3) AND (x < 100H) THEN 3 digits are written
  145.     ELSE 6 digits are written
  146. *)
  147.  
  148. PROCEDURE WriteHex( x, n :CARDINAL );
  149. (*
  150.     write x in hexadecimal in a right justified field of at least n characters.
  151.     IF (n <= 2) AND (x < 100H) THEN 2 digits are written
  152.     ELSE 4 digits are written
  153. *)
  154.  
  155. PROCEDURE WriteWrd( w :WORD );
  156. (*
  157.     write w to the output file.
  158.     only legal when output is being redirected to a file.
  159. *)
  160.  
  161. PROCEDURE ReadLongInt( VAR x :LONGINT );
  162. (*
  163.     a string is read from the input device and is then converted to
  164.     a LONGINT.
  165. *)
  166.  
  167. PROCEDURE ReadLongCard( VAR x :LONGCARD );
  168. (*
  169.     a string is read from the input device and is then converted to
  170.     a LONGCARD.
  171. *)
  172.  
  173. PROCEDURE WriteLongInt( x :LONGINT; n :CARDINAL );
  174. (*
  175.     write the LONGINT right justified in a field of at least n characters.
  176. *)
  177.  
  178. PROCEDURE WriteLongCard( x :LONGCARD; n :CARDINAL );
  179. (*
  180.     write the LONGCARD right justified in a field of at least n characters.
  181. *)
  182.  
  183. END InOut.